home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / icm-exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.3 KB  |  91 lines

  1. /*
  2. \funcref{main}{void main (\params)}
  3.     {
  4.         {int} {argc} {argument count}
  5.         {char} {**argv} {array of arguments}
  6.         {char} {**envp} {array of environment settings}
  7.     }
  8.     {}
  9.     {getvar(), process(), envp2list(), newvar()}
  10.     {}
  11.     {icm-exec.c}
  12.     {
  13.  
  14.         The {\em main()} function opens the binary makefile, reads the offsets
  15.         of the variables and strings sections, calls {\em getvar()} to retrieve
  16.         the variables, pushes {\em argc}, {\em argv} and {\em envp}
  17.         onto the {\em icmake}
  18.         stack and then calls {\em process()} to execute the makefile.
  19.  
  20.         The exit value of {\em main()} is held in the global variable {\em
  21.         retval} (see also {\em fun\_ret()}).
  22.  
  23.         Function {\em cleanup()} is attached to the `at-exit' list for DOS 
  24.     systems. This is necessary so that the startup working directory is 
  25.     restored. For UNIX systems, no {\em atexit()} list is created.
  26.     
  27.     }
  28. */
  29.  
  30. #ifdef MSDOS
  31. #define LIBREQUEST
  32. #pragma comment (lib, "icmexec")
  33. #pragma comment (lib, "../rss/icrss")
  34. #endif
  35.  
  36. #include "icm-exec.h"
  37.  
  38. void main (argc, argv, envp)
  39. int argc;
  40. char **argv;
  41. char **envp;
  42. {
  43.     register char
  44.         *progname;
  45.     register int
  46.         i;
  47.     VAR_
  48.         tmp;
  49.  
  50. #ifdef MSDOS
  51.     atexit (cleanup);
  52. #endif    
  53.     signal (SIGINT, abnormal);
  54.     getcwd (orgdir, _MAX_PATH - 1);
  55.  
  56.     if (argc < 2)
  57.     {
  58.         copyright ("ICMAKE Binary Makefile Executor", version, release, 1);
  59.         progname = program_name (argv [0]);
  60.         printf ("This program is run as a child process of icmake.\n"
  61.                 "Usage: %s bimfile\n"
  62.                 "where: bimfile - binary makefile to execute\n\n"
  63.             , progname);
  64.         exit (1);
  65.     }
  66.  
  67.     if (! (infile = fopen (argv [1], READBINARY)) )
  68.         error ("cannot open bimfile %s for reading", argv [1]);
  69.  
  70.     headerp = readheader (infile, version [0]);
  71.     if ( (INT16)(nvar = getvar (infile, headerp, &var)) == -1 )
  72.         error ("invalid macro file, cannot read variable section");
  73.  
  74.     fseek (infile, headerp->offset[3], SEEK_SET);
  75.  
  76.     push (envp2list (envp));
  77.  
  78.     tmp = newvar (e_list);
  79.     for (i = 1; i < argc; i++)
  80.         tmp = addtolist (tmp, argv [i]);
  81.     push (tmp);
  82.  
  83.     tmp.type = e_int;
  84.     tmp.vu.intval = argc - 1;
  85.     push (tmp);
  86.  
  87.     process ();
  88.  
  89.     exit (retval);
  90. }
  91.